#!/bin/bash
#
# /etc/rc.d/hdapsd: start/stop hdaps daemon
#

[[ -r /etc/hdapsd.conf ]] && . /etc/hdapsd.conf

pid=$(cat /var/run/hdapsd.pid 2>/dev/null)

case "$1" in
    start)
        # setup hdaps daemon startup parameters
        HDAPSD_OPTS="-bp"
        if [ -z "$DEVICE" ]; then
            HDAPSD_OPTS="$HDAPSD_OPTS -d sda"
        else
            for i in ${DEVICE[@]}; do
                HDAPSD_OPTS="$HDAPSD_OPTS -d $i"
            done
        fi
        [ -n "$SENSITIVITY" ] && HDAPSD_OPTS="$HDAPSD_OPTS -s $SENSITIVITY"
        [ "$ADAPTIVE" = "yes" ] && HDAPSD_OPTS="$HDAPSD_OPTS -a"
        [ "$SYSLOG" = "yes" ] && HDAPSD_OPTS="$HDAPSD_OPTS -l"
        [ "$FORCE" = "yes" ] && HDAPSD_OPTS="$HDAPSD_OPTS -f"

        # if daemon is not running yet, start it
        [ -z "$pid" ] && /usr/sbin/hdapsd $HDAPSD_OPTS
        ;;
    stop)
        [ -n "$pid" ] && kill $pid
        ;;
    restart)
        $0 stop
        sleep 2
        $0 start
        ;;
    *)
        echo "usage: $0 [start|stop|restart]"
        ;;
esac

# End of file
